<template>
    <div class="page-wrapper">
        <div class="page-wrapper__body">
            <div class="page-container is-form" v-loading="isLoading">
                <el-form ref="ibmJobForm" :model="model" label-width="140px" label-position="left">
                    <div class="block-title"><i>¶</i><el-button type="default" icon="el-icon-back" round size="mini" class="more" @click="onBack">返回</el-button> 岗位基本信息</div>
                    <div style="height:20px;"></div>
                    <el-form-item label="招聘岗位: ">
                        <el-input placeholder="请输入招聘岗位" v-model="model.jobTitle"></el-input>
                    </el-form-item>
                    <el-form-item label="岗位类别: ">
                        <el-input placeholder="请输入岗位类别" v-model="model.jobType"></el-input>
                    </el-form-item>
                    <el-form-item label="岗位职责: ">
                        <el-input type="textarea" :rows="3" placeholder="请输入岗位职责" v-model="model.jobDesc"></el-input>
                    </el-form-item>
                    <el-form-item label="任职要求: ">
                        <el-input type="textarea" :rows="3" placeholder="请输入任职要求" v-model="model.requirement"></el-input>
                    </el-form-item>
                    <!--<el-form-item label="工作地点: ">
                        <el-input placeholder="请输入工作地点" v-model="model.workPlace"></el-input>
                    </el-form-item>-->
                    <el-form-item label="学历要求: ">
                        <el-input placeholder="请输入学历要求" v-model="model.eduDegree"></el-input>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <div class="form-footer">
            <el-button type="primary" @click="onSubmit" style="width:120px;">保存</el-button>
            <el-button @click="onBack">取 消</el-button>
        </div>
    </div>
</template>

<script>
    import {getDetail,updateOne} from "../../api/job/ibm";

    export default {
        name: "edit",
        data(){
            return{
                model:{},
                params:{
                    id:0
                },
                isLoading:false
            }
        },
        methods:{
            onSubmit(){
                this.isLoading = true;
                this.$refs['ibmJobForm'].validate((valid) => {
                    if(valid){
                        this.handleSubmit();
                    }
                })
            },
            onBack(){
                this.$router.push('/ibm/job/list')
            },
            async handleSubmit(){
                let resp = await updateOne({entity: this.model});
                if(this.qUtil.validResp(resp)){
                    this.isLoading = false;
                    this.$message({
                        message: '修改成功！',
                        type: 'success'
                    });
                    this.onBack();
                }
                this.isLoading = false;
            },
            async loadData(){
                if(this.params.id <= 0){
                    this.$alert('参数错误', '提示', { confirmButtonText: '确定',okFn: ()=> {
                        this.onBack()
                    }});
                    return false;
                }
                this.isLoading = true;
                let resp = await getDetail(this.params.id);
                if(!this.qUtil.validResp(resp)){
                    this.isLoading = false;
                    this.$alert('请求数据失败!', '提示', {
                        confirmButtonText: '确定',
                        okFn: ()=> {
                            this.onBack()
                        }
                    });
                    return false;
                }
                this.model = resp.data.model || {};
                console.log(this.model);
                this.isLoading = false;
            },

        },
        mounted(){
            this.params.id = parseInt(this.$route.query.id) || 0;
            this.loadData();
        }
    }
</script>

<style scoped>

</style>